# Alexander F. Gazmararian
# afg2@princeton.edu
rm(list = ls())
gc()
# Load packages
library(tidyverse)
library(modelsummary)
# Load data
g <- readRDS("data/NatQual_August22.rds")
# Code remaining covariates
g$income5 <- gsub("[$]", "", g$income5)
# Get summary statistics for August
file <- "tables/tbl_summarystat_balzan.txt"
datasummary(
  formula = (Age = age) + (Female)  + Black + Hispanic + (College = CollegeDegree) +
    (Democrat = Dem) + (Republican = Rep) + (Liberal = Lib) + (Conservative = Con) + (Income = income5) ~ Mean + SD + N + Percent(),
  data = g,
  fmt = 2,
  escape = FALSE,
  output = "latex"
) %>%
  cat(., file = file)
# Trim table shell
tbl <- readLines(file, warn = FALSE)
tbl <- tbl[-c(1,2,length(tbl))]
cat(tbl, file = file)